A color of a palette you already have, to draw a rectangle in: palette_color(hud_colors, 5) is the color in the sixth place (slot 5, counting from 0) of the palette hud_colors. Use it where a COLOR_ name goes: draw_rect_fill(10, 10, 40, 6, palette_color(hud_colors, 5)). slot is 0 to 15.
Works differently on Game Boy - A rectangle in a palette_color shows the nearest of the four greys to that color of your palette; colors that come out the same grey look alike. Name the palette and a plain slot number.
Works differently on Game Boy Color - A rectangle in a palette_color takes that color of your palette, shared with the other rectangle colors (3 to a free sprite palette; extra ones become the nearest). Name the palette and a plain slot number.
On other consoles this differs: see Side by side and How the consoles differ.
palette_color(palette, slot) -> shape_color| Name | Type |
|---|---|
palette | palette |
slot | int |
shape_color
A color of a palette you already have, to draw a rectangle in. palette_color(pal_doc_gold, 5) is the color in the sixth place of the palette pal_doc_gold (the places count from 0, so slot is 0 to 15, the same numbers the Paint tab shows). Use it wherever a COLOR_ name goes: in draw_rect_fill, draw_rect and their _anchored forms.
In the editor, when you are typing the color of one of those calls, the list offers a color from a color table: it opens a small window that shows every palette of your game with its 16 colors, and picking one writes the call for you.
// Draw event: a bar in the fifth color of the palette the sprites already wear
draw_rect_fill(x - 16, y - 23, 32, 6, palette_color(pal_doc_gold, 4));// Draw GUI event: an outline in the first color of the same palette
draw_rect(4, 4, 60, 10, palette_color(pal_doc_gold, 0));A rectangle drawn with a COLOR_ name takes its colors from the engine's own color table. That table is a sprite palette of its own: one of the console's 16, taken the moment any such rectangle is drawn and kept for as long as one is. palette_color draws the rectangle in the palette you name instead. If a sprite wearing that palette is on the screen, the rectangle shares its place and costs no palette at all. If none is, the palette is loaded the way a sprite's is, and the engine's own color table is never made for it.
To get the saving, name a palette your sprites already wear. Two palettes with the same 16 colors count as the same one to the console, even if they are two files; a palette with a single color different is another palette and takes its own place. A game can name up to 8 different palettes this way, and each must have 16 colors (the kind a sprite is drawn with): another size draws nothing and a development build says so. palette_color(nothing, 0) is black. Only the four rectangle calls are made for it: a screen fade, a screen flash and a background edge also take a color, but a palette color is not one of theirs, so do not give it to them.
A rectangle in a palette_color color is built from several sprites, the way a rectangle of a size that is not a small exact one is (see draw_rect_fill), and an outline from plain sprites laid end to end. A game that never calls palette_color carries none of that. A rectangle drawn with a COLOR_ name is not changed, and the two can be used together in one game.
A rectangle drawn in a COLOR_ name uses the engine’s own color table, which takes one of the console’s 16 sprite palettes as soon as any such rectangle is drawn. A rectangle drawn with palette_color uses the palette you name instead: if a sprite showing that palette is on the screen the rectangle shares its place, so it costs no palette at all; if none is, the palette is loaded like a sprite’s (and freed when nothing shows it), and the engine’s own color table is never made for it. The palette has to have 16 colors, the kind a sprite uses; a palette of another size draws nothing and a development build says so. Share a palette with your sprites to get the saving: a palette with the same colors, even a copy, is the same palette to the console, but a palette with one color different is another one. A game can name up to 8 different palettes this way. A rectangle drawn this way is built from several sprites like any rectangle that is not a small exact size (see draw_rect_fill), and an outline (draw_rect) from plain sprites laid end to end, so it costs a little more cartridge space than a COLOR_ rectangle of a small size, and nothing at all in a game that never calls palette_color. slot below 0 reads as 0 and above 15 as 15. palette_color(nothing, 0) is COLOR_BLACK. Only the four rectangle calls are made for it: screen_fade, screen_flash and a background edge take a color too, but a palette color is not one of theirs, so do not give it to them.